/* vim: set expandtab shiftwidth=4: -*- mode: c++; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: nil -*-
qRPG
An RPG written to test Qt's Graphics View framework
Copyright (C) 2006 Wesley Crossman
Email: wesley@crossmans.net

You can redistribute and/or modify this software under the terms of the GNU
General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA */

#ifndef GAMEBOARDSCENE_H
#define GAMEBOARDSCENE_H

#include "DynamicArray.h"
#include <QSize>
#include <QMap>
#include <QHash>
#include <QPair>
#include <QGraphicsScene>
#include <QTextStream>
#include <QObject>
class BoardEntry;
class Hero;
class GameItem;
class Hero;
class QTimer;

class GameBoardScene : public QGraphicsScene {
Q_OBJECT
protected:
    int tileSize;
    QSize boardSize, physicalSize;
    QMap < QString, QPixmap > mapping;
    QHash < QString, int > layerNames;
    QList < GameItem * > items;
    QList < QPair < QString, int > > statusEntries;
    QTimer *statusTimer;

    QGraphicsRectItem *border;
    void deleteBoardEntries();
    void resetBoard();
    void keyPressEvent(QKeyEvent *);
protected slots:
    void ensureHeroVisible();
    void tick();
public:
    DynamicArray < BoardEntry * > array;
    Hero *me;
    GameBoardScene(QObject *parent = 0);
    virtual ~GameBoardScene() {}
    virtual void loadBoard(QTextStream &);
    QList < GameItem * > getInventory();
    QList < GameItem * > getUnderFoot();
    QList < GameItem * > getAtPosition(QPoint pos);
    QList < GameItem * > GameBoardScene::getAtPosition(int x, int y) {
        return getAtPosition(QPoint(x, y));
    }
    QPointF toPhysical(qreal x, qreal y) {
        return QPointF(x * tileSize, y * tileSize);
    }
    QPointF toPhysical(QPointF point) {return toPhysical(point.x(), point.y());}
    QPointF toPhysical(QPoint point) {return toPhysical(point.x(), point.y());}
    QPointF toLogical(qreal x, qreal y) {
        return QPointF(x / qreal(tileSize), y / qreal(tileSize));
    }
    int getTileSize() {return tileSize;}
    QSize getBoardSize() {return boardSize;}
    int getLayerIndex(QString name) {return layerNames.value(name, -1);}
    Hero *getMe() {return me;}
    void changeLayerZValue(int layer, int change);
    
    void showMessage(const QString &message, int timeout);

    void registerItem(GameItem *);
    void unregisterItem(GameItem *);
protected slots:
    void updateMessage();
signals:
    void playerMoved();
    void playerInventoryChanged();
    void sigShowMessage(const QString &message);
};

#endif

